package threading;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo21 {
    public static void main(String[] args) {
        BlockingDeque<Integer>  blockingDeque = new LinkedBlockingDeque<>();

        //消费者
        Thread t1 = new Thread( () -> {
            while (true) {
                try {
                    int value = blockingDeque.take();
                    System.out.println("消费元素" + value);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread t2 = new Thread( () -> {
           int count = 0;
           while (true) {
               try {
                   blockingDeque.put(count);
                   System.out.println("生产元素" + count);
                   count++;
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });

        t1.start();
        t2.start();
    }
}
